package com.brower.project.ui.activity

import android.webkit.*
import com.brower.project.R
import com.brower.project.base.BaseActivity
import com.brower.project.base.NormalViewModel
import com.brower.project.databinding.ActivityWebBinding

class WebActivity : BaseActivity<ActivityWebBinding, NormalViewModel>() {
    override fun layoutId() = R.layout.activity_web

    override fun initView() {
        super.initView()
        val webView = mBinding!!.webView
        val settings = webView.settings
        settings.allowFileAccess = true
        settings.useWideViewPort = true
        settings.loadWithOverviewMode = true

        settings.cacheMode = WebSettings.LOAD_NO_CACHE
        settings.defaultTextEncodingName = "utf-8"
        settings.loadsImagesAutomatically = true
        settings.domStorageEnabled = true
        settings.databaseEnabled = true
        settings.setRenderPriority(WebSettings.RenderPriority.HIGH)
        settings.blockNetworkImage = true

        webView.webChromeClient = object : WebChromeClient() {
            override fun onReceivedTitle(view: WebView, title: String) {
                super.onReceivedTitle(view, title)
                val forwardList = view.copyBackForwardList()
                val item = forwardList.currentItem
//                if (item != null) {
//                    baseWebTitle.visibility = View.VISIBLE
//                    baseWebTitle.text = item.title
//                } else {
//                    baseWebTitle.visibility = View.GONE
//                }
            }

            override fun onProgressChanged(webView: WebView?, i: Int) {
                super.onProgressChanged(webView, i)
//                if (i < 100) {
//                    business_version_upload_dialog_progress.visibility = View.VISIBLE
//                    business_version_upload_dialog_progress.progress = i
//                } else {
//                    business_version_upload_dialog_progress.visibility = View.GONE
//                }
            }

        }
    }
}